function loadJScript() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://api.map.baidu.com/api?type=webgl&v=2.0&ak=drGhos38GdxD7WMppGW4NdswaQVeXEhX&callback=init';
    document.body.appendChild(script);
}
//第一种，使用while循环
function sleep(delay) {
    var start = (new Date()).getTime();
    while ((new Date()).getTime() - start < delay) {
        continue;
    }
}

let mapObj;

function init() {
    // var map = new BMapGL.Map('container'); // 创建Map实例
    var point = new BMapGL.Point(116.404, 39.915); // 创建点坐标
    // map.centerAndZoom(point, 10);
    // map.enableScrollWheelZoom(); // 启用滚轮放大缩小
    var map = new BMapGL.Map('container', {
        enableDblclickZoom: false,
        displayOptions: {
            building: false
        }
    });

    mapObj = map;

    map.enableScrollWheelZoom(true);

    var map1 = new BMapGL.Map('container1', {
        enableDblclickZoom: false,
        displayOptions: {
            building: false
        }
    });

    map1.enableScrollWheelZoom(true);
    map1.setMapStyleV2({ styleJson: styleJson2 });
    map.setMapStyleV2({ styleJson: styleJson2 });


    var bd = new BMapGL.Boundary();
    bd.get('顺义区', function (rs) {
        // console.log('外轮廓：', rs.boundaries[0]);
        // console.log('内镂空：', rs.boundaries[1]);
        var hole = new BMapGL.Polygon(rs.boundaries, {
            fillColor: 'blue',
            fillOpacity: 0.2
        });
        // map.addOverlay(hole);
        map1.addOverlay(hole);
    });
    setTimeout(function () {
        // map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 14);  // 初始化地图,设置中心点坐标和地图级别
        map.centerAndZoom('乐平市', 14);  // 初始化地图,设置中心点坐标和地图级别
        map1.centerAndZoom(new BMapGL.Point(116.718, 40.142), 11);
    }, 1000);


    Array.from(document.getElementsByClassName("events")).forEach(function (item) {
        console.log(item.id);
    });

    setInterval(() => {
        let showMap = document.getElementById('objTrace').children
        const newArr = Array.from(showMap)
        console.log(showMap)
        newArr.forEach((item) => {
            console.log('item', item)
            console.log('aria-checked', item.getAttribute('aria-checked'))
            if (item.getAttribute('aria-checked') === "true") {
                console.log("228")
                map.centerAndZoom('合肥市',14)
            }
        })
    }, 1000)

    var polyline = new BMapGL.Polyline([
        new BMapGL.Point(116.299, 39.910),
        new BMapGL.Point(116.305, 39.920),
        new BMapGL.Point(116.411, 39.900),
        new BMapGL.Point(116.404, 39.9310),
        new BMapGL.Point(116.438, 39.890),
        new BMapGL.Point(116.475, 39.8910)
    ], {
        strokeColor: 'green',
        strokeWeight: 5,
        strokeOpacity: 1.0
    });

    map.addOverlay(polyline);          //增加折线


}
window.onload = loadJScript; // 异步加载地图
